﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace FormsCheck
{
    class Program
    {
        static void Main(string[] args)
        {
            TestCheck();
            Console.ReadLine();
        }

        [DllImport("user32.dll", EntryPoint = "FindWindow")]
        private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
        /// <summary>
        /// 窗口是否还存在
        /// </summary>
        /// <param name="hWnd"></param>
        /// <returns></returns>
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern bool IsWindow(IntPtr hWnd);

        public static int SW_HIDE = 0;

        public static int SW_SHOWNORMAL = 1;

        public static int SW_SHOWMINIMIZED = 2;

        public static int SW_SHOWMAXIMIZED = 3;

        public static int SW_MAXIMIZE = 3;

        public static int SW_SHOWNOACTIVATE = 4;

        public static int SW_SHOW = 5;

        public static int SW_MINIMIZE = 6;

        public static int SW_SHOWMINNOACTIVE = 7;

        public static int SW_SHOWNA = 8;

        public static int SW_RESTORE = 9;

        [DllImport("user32.dll", EntryPoint = "ShowWindow", CharSet = CharSet.Auto)]

        public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);


        /// <summary>
        /// 窗口是否最小化
        /// </summary>
        /// <param name="hWnd"></param>
        /// <returns></returns>
        [DllImport("user32.dll")]
        public static extern bool IsIconic(IntPtr hWnd);
        [DllImport("user32.dll")]
        private static extern bool SetForegroundWindow(IntPtr hWnd);
        private static void TestCheck()
        {
            var ptr = FindWindow(null, "1");
            SetForegroundWindow(ptr);
            Console.ReadLine();
            Console.WriteLine(8);
            ShowWindow(ptr, 8);
            for (int i = 1; i < 10; i++)
            {
                Console.ReadLine();
                Console.WriteLine(i);
                ShowWindow(ptr, i);
            }
            Console.WriteLine(ptr != IntPtr.Zero ? ptr.ToString() : "没有");
        }
    }
}
